package yl.hs.bmipfull.controllers.laboratorydata;


import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import yl.hs.bmipfull.controllers.ControllerBase;
import yl.hs.bmipfull.service.laboratorydata.ILabRmCementReportItemService;
import yl.hs.bmipfull.viewmodels.PageQuery;
import yl.hs.bmipfull.viewmodels.SubmitModel;
import yl.hs.bmipfull.viewmodels.WebResult;

/**
 * @author 谢东
 * @apiNote 检测报告-水泥报告控制层
 * @since 2022年06月29日 16时12分39秒
 */
@Api(value = "检测报告-水泥报告Web接口", tags = "管理--检测报告-水泥报告操作")
@RequestMapping(value = "api/lab/report/cement/")
@RestController
public class LabRmCementReportItemController extends ControllerBase {

    @Autowired
    ILabRmCementReportItemService service;

    @ApiOperation(value = "查询检测报告-水泥报告", notes = "查询检测报告-水泥报告")
    @RequestMapping(value = "query", method = RequestMethod.POST)
    public WebResult queryList(@ApiParam(value = "查询条件") @RequestBody PageQuery pageQuery) {
        try {
            return success("查询成功", service.queryList(pageQuery));
        } catch (Exception e) {
            return error(e);
        }
    }

    @ApiOperation(value = "查询检测报告-水泥报告", notes = "分页查询检测报告-水泥报告")
    @RequestMapping(value = "query/{rowNum}/{page}", method = RequestMethod.POST)
    public WebResult queryPage(@RequestBody PageQuery query,
                               @ApiParam(value = "页码") @PathVariable int page,
                               @ApiParam(value = "每页条数") @PathVariable int rowNum) {
        try {
            var result = service.queryPage(query, rowNum, page);
            return success("ok", result);
        } catch (Exception ee) {
            return error(ee);
        }
    }


    @ApiOperation(value = "查询检测报告-水泥报告", notes = "根据检测报告-水泥报告编号查询检测报告-水泥报告")
    @RequestMapping(value = "/{sn}", method = RequestMethod.GET)
    public WebResult findBySn(@ApiParam(value = "编号") @PathVariable String sn) {
        return success("查询成功", service.findBySn(sn));
    }
    @ApiOperation(value = "查询检测报告-水泥报告", notes = "根据检测报告-水泥报告编号查询检测报告-水泥报告")
    @RequestMapping(value = "ReportSN/{ReportSN}", method = RequestMethod.GET)
    public WebResult getByReportSN(@ApiParam(value = "编号") @PathVariable String ReportSN) {
        return success("查询成功", service.getByReportSN(ReportSN));
    }


    @ApiOperation(value = "保存检测报告-水泥报告", notes = "查询/更新检测报告-水泥报告信息")
    @RequestMapping(value = "save", method = RequestMethod.PUT)
    public WebResult saveLabRmCementReportItem(@ApiParam(value = "提交信息") @RequestBody SubmitModel submitModel) {
        Integer result;
        try {
            result = service.saveLabRmCementReportItem(submitModel.getData(), submitModel.getSn());
            if (result > 0) {
                return success("保存成功");
            } else {
                return fail("数据未保存");
            }
        } catch (Exception e) {
            return error(e);
        }

    }

    @ApiOperation(value = "删除检测报告-水泥报告信息", notes = "根据检测报告-水泥报告编号删除系检测报告-水泥报告信息")
    @RequestMapping(path = "", method = RequestMethod.DELETE)
    public WebResult delete(@ApiParam(value = "检测报告-水泥报告编号", name = "sn", allowMultiple = true, required = true) @RequestParam("sn") String[] sn) {
        if (service.delete(sn) > 0) {
            return success("删除成功");
        } else {
            return fail("删除失败");
        }

    }
}